package com.nine.sensitive.controller;

import com.nine.sensitive.component.DesensitiveComponent;
import com.nine.sensitive.model.User;
import com.nine.sensitive.model.vo.UserVo;
import com.nine.sensitive.result.R;
import com.nine.sensitive.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @Autowired
    private DesensitiveComponent desensitiveComponent;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public R getUser(@PathVariable("id") Long id) {
        User user = userService.getById(id);
        UserVo userVo = new UserVo();
        // 处理映射关系,同时进行脱敏
        desensitiveComponent.desensitize(user, userVo);
        return R.ok(userVo);
    }

}
